/*
 * DrawableString.cpp
 *
 *  Created on: 2011-4-6
 *      Author: wangchao
 */

#include "YuebaoSplashString.h"
#include "fGfxEngine.h"
#define SCROLL_STEP 1
#define SCROLL_MARG 10

DrawableString::DrawableString( ) :
    _scrollLength( 0 ), _areaWidth( 0 ), _textWidth( 0 )
{
}

DrawableString::~DrawableString( )
{
}

void DrawableString::Draw( fDrawer& gfx, TInt aSpeed, TInt aPosX, TInt aPosY, TInt aColor, const CFont * aFont, const TDesC16& aStr, bool bScroll )
{
    if( _textWidth <= _areaWidth || !bScroll )
    {
        TRect clipRect = gfx.GetClipRect( );
        TRect stringRect( aPosX, 0, aPosX + _areaWidth, gfx.iScreenSize.iHeight );
        stringRect.Intersection( clipRect );
        gfx.SetClipRect( stringRect );
        gfx.DrawString( aPosX, aPosY, aColor, aFont, aStr );
        gfx.SetClipRect( clipRect );
    }
    else
    {
        int tempAlgin = gfx.GetAlignStyle( );
        gfx.SetAlignStyle( f_GFX_PAS_LEFT );
        int speed = aSpeed;
        if( _scrollLength >= _textWidth - _areaWidth )
        {
            _flag = true;
        }
        else if( _scrollLength < 0 )
        {
            _flag = false;
        }
        else
        {

        }

        if( _flag )
        {
            _scrollLength -= aSpeed;
        }
        else
        {
            _scrollLength += aSpeed;
        }
        /* if( _scrollLength > ( _textWidth - _areaWidth + SCROLL_MARG) )
         {
         _scrollLength = -aSpeed( _areaWidth - aPosX + SCROLL_MARG );
         }
         else
         {
         _scrollLength += aSpeed;
         }*/

        TRect clipRect = gfx.GetClipRect( );
        TRect stringRect( aPosX, 0, aPosX + _areaWidth, gfx.iScreenSize.iHeight );
        stringRect.Intersection( clipRect );
        gfx.SetClipRect( stringRect );
        gfx.DrawString( aPosX - _scrollLength, aPosY, aColor, aFont, aStr );
        gfx.SetClipRect( clipRect );

        /*gfx.SetClipRect( TRect( aPosX, 0, aPosX + _areaWidth, gfx.iScreenSize.iHeight ) );
         gfx.DrawString( aPosX - _scrollLength, aPosY, aColor, aFont, aStr );
         gfx.ResetClipRect( );//( TRect( 0, 0, gfx.iScreenSize.iWidth, gfx.iScreenSize.iHeight ) );*/
        gfx.SetAlignStyle( tempAlgin );
    }
}
